1 /**
2  * This file is part of libphidget21
3  *
4  * Copyright 2006-2015 Phidgets Inc <patrick@phidgets.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see 
18  * <http://www.gnu.org/licenses/>
19  */
20 module phidget21.phidcommon;
21 import phidget21.phidconst;
22 
23 extern(C) __gshared {
24 	struct _CPhidget;
25 	alias CPhidgetHandle = _CPhidget*;
26 
27 	struct _CPhidget_Timestamp {
28 		int seconds;       /**< Number of seconds since timing began */
29 		int microseconds;  /**< Number of microseconds since last second passed - range is 0 - 999999 */
30 	}
31 	alias CPhidget_Timestamp = _CPhidget_Timestamp;
32 	alias CPhidget_TimestampHandle = _CPhidget_Timestamp*;
33 
34 	enum CPhidget_DeviceUID {
35 		PHIDUID_NOTHING = 1,
36 		
37 		PHIDUID_ACCELEROMETER_2AXIS_2G,
38 		PHIDUID_ACCELEROMETER_2AXIS_10G,
39 		PHIDUID_ACCELEROMETER_2AXIS_5G,
40 		PHIDUID_ACCELEROMETER_3AXIS_3G,
41 		
42 		PHIDUID_ADVANCEDSERVO_1MOTOR,
43 		
44 		PHIDUID_ADVANCEDSERVO_8MOTOR,
45 		PHIDUID_ADVANCEDSERVO_8MOTOR_PGOOD_FLAG,
46 		PHIDUID_ADVANCEDSERVO_8MOTOR_CURSENSE_FIX,
47 		
48 		PHIDUID_ANALOG_4OUTPUT,
49 		
50 		PHIDUID_BRIDGE_4INPUT_GAINBUG,
51 		PHIDUID_BRIDGE_4INPUT,
52 		
53 		PHIDUID_ENCODER_1ENCODER_1INPUT_OLD,
54 		PHIDUID_ENCODER_1ENCODER_1INPUT_v1,
55 		PHIDUID_ENCODER_1ENCODER_1INPUT_v2,
56 		PHIDUID_ENCODER_HS_1ENCODER,
57 		PHIDUID_ENCODER_HS_4ENCODER_4INPUT,
58 		
59 		PHIDUID_FREQUENCYCOUNTER_2INPUT,
60 		
61 		PHIDUID_GPS,
62 		
63 		PHIDUID_INTERFACEKIT_0_0_4_NO_ECHO,
64 		PHIDUID_INTERFACEKIT_0_0_4,
65 		PHIDUID_INTERFACEKIT_0_0_8,
66 		PHIDUID_INTERFACEKIT_0_5_7,
67 		PHIDUID_INTERFACEKIT_0_8_8_w_LCD,
68 		PHIDUID_INTERFACEKIT_0_16_16_NO_ECHO,
69 		PHIDUID_INTERFACEKIT_0_16_16_BITBUG,
70 		PHIDUID_INTERFACEKIT_0_16_16,
71 		PHIDUID_INTERFACEKIT_2_2_2,
72 		PHIDUID_INTERFACEKIT_2_8_8,
73 		PHIDUID_INTERFACEKIT_4_8_8,
74 		PHIDUID_INTERFACEKIT_8_8_8_NO_ECHO,
75 		PHIDUID_INTERFACEKIT_8_8_8,
76 		PHIDUID_INTERFACEKIT_8_8_8_FAST,
77 		PHIDUID_INTERFACEKIT_8_8_8_w_LCD_NO_ECHO,
78 		PHIDUID_INTERFACEKIT_8_8_8_w_LCD,
79 		PHIDUID_INTERFACEKIT_8_8_8_w_LCD_FAST,
80 		PHIDUID_INTERFACEKIT_TOUCH_SLIDER,
81 		PHIDUID_INTERFACEKIT_TOUCH_ROTARY,
82 		
83 		PHIDUID_IR,
84 		
85 		PHIDUID_LED_64,
86 		PHIDUID_LED_64_ADV,
87 		PHIDUID_LED_64_ADV_M3,
88 		
89 		PHIDUID_MOTORCONTROL_1MOTOR,
90 		PHIDUID_MOTORCONTROL_HC_2MOTOR,
91 		PHIDUID_MOTORCONTROL_LV_2MOTOR_4INPUT,
92 		
93 		PHIDUID_PHSENSOR,
94 		
95 		PHIDUID_RFID_OLD,
96 		PHIDUID_RFID,
97 		PHIDUID_RFID_2OUTPUT_NO_ECHO,
98 		PHIDUID_RFID_2OUTPUT,
99 		PHIDUID_RFID_2OUTPUT_READ_WRITE,
100 		
101 		PHIDUID_SERVO_1MOTOR_OLD,
102 		PHIDUID_SERVO_4MOTOR_OLD,
103 		PHIDUID_SERVO_1MOTOR_NO_ECHO,
104 		PHIDUID_SERVO_1MOTOR,
105 		PHIDUID_SERVO_4MOTOR_NO_ECHO,
106 		PHIDUID_SERVO_4MOTOR,
107 		
108 		PHIDUID_SPATIAL_ACCEL_3AXIS_1049,
109 		PHIDUID_SPATIAL_ACCEL_3AXIS_1041,
110 		PHIDUID_SPATIAL_ACCEL_3AXIS_1043,
111 		PHIDUID_SPATIAL_ACCEL_GYRO_COMPASS_1056,
112 		PHIDUID_SPATIAL_ACCEL_GYRO_COMPASS_1056_NEG_GAIN,
113 		PHIDUID_SPATIAL_ACCEL_GYRO_COMPASS_1042,
114 		PHIDUID_SPATIAL_ACCEL_GYRO_COMPASS_1044,
115 		
116 		PHIDUID_STEPPER_BIPOLAR_1MOTOR,
117 		PHIDUID_STEPPER_BIPOLAR_1MOTOR_M3,
118 		PHIDUID_STEPPER_UNIPOLAR_4MOTOR,
119 		
120 		PHIDUID_TEMPERATURESENSOR_OLD,
121 		PHIDUID_TEMPERATURESENSOR,
122 		PHIDUID_TEMPERATURESENSOR_AD22100,
123 		PHIDUID_TEMPERATURESENSOR_TERMINAL_BLOCKS,
124 		PHIDUID_TEMPERATURESENSOR_4,
125 		PHIDUID_TEMPERATURESENSOR_IR,
126 		
127 		PHIDUID_TEXTLCD_2x20,
128 		PHIDUID_TEXTLCD_2x20_w_8_8_8,
129 		PHIDUID_TEXTLCD_2x20_w_8_8_8_BRIGHTNESS,
130 		PHIDUID_TEXTLCD_ADAPTER,
131 		
132 		PHIDUID_TEXTLED_1x8,
133 		PHIDUID_TEXTLED_4x8,
134 		
135 		PHIDUID_WEIGHTSENSOR,
136 		
137 		PHIDUID_GENERIC,
138 		PHIDUID_FIRMWARE_UPGRADE
139 	}
140 
141 	/**
142 	 * Opens a Phidget.
143 	 *
144   	 * Params:
145  	 * 	phid = A phidget handle.
146 	 *	serialNumber = Serial number. Specify -1 to open any.
147    	 */
148 	int function(CPhidgetHandle phid, int serialNumber) CPhidget_open;
149 
150 	/**
151 	 * Opens a Phidget by label.
152 	 *
153 	 * Params:
154 	 * 	phid = A phidget handle.
155  	 *	label = Label string. Labels can be up to 10 characters (UTF-8 encoding). Specify NULL to open any.
156 	 */
157 	int function(CPhidgetHandle phid, const char* label) CPhidget_openLabel;
158 	
159 	/**
160 	 * Closes a Phidget.
161 	 *
162 	 * Params:
163 	 *	phid = An opened phidget handle.
164 	 */
165 	int function(CPhidgetHandle phid) CPhidget_close;
166 	
167 	/**
168 	 * Frees a Phidget handle.
169 	 *
170  	 * Params:
171 	 * 	phid = A closed phidget handle.
172 	 */
173 	int function(CPhidgetHandle phid) CPhidget_delete;
174 
175 	alias CPhidget_set_OnDetach_Handler_Func = extern(C) int function(CPhidgetHandle phid, void* userPtr);
176 	/**
177  	 * Sets a detach handler callback function. This is called when this Phidget is unplugged from teh system.
178 	 *
179 	 * Params:
180 	 *	phid = A phidget handle.
181 	 *	fptr = Callback function pointer.
182 	 *	userPtr = A pointer for use by the user - this value is passed back into the callback function.
183 	 */
184 	int function(CPhidgetHandle phid, CPhidget_set_OnDetach_Handler_Func fptr, void* userPtr) CPhidget_set_OnDetach_Handler;
185 
186 	alias CPhidget_set_OnAttach_Handler_Func = extern(C) int function(CPhidgetHandle phid, void* userPtr);
187 	/**
188 	 * Sets an attach handler callback function. This is called when this Phidget is plugged into the system, and is ready for use.
189 	 *
190 	 * Params:
191 	 *	phid = A phidget handle.
192 	 *	fptr = Callback function pointer.
193 	 *	userPtr = A pointer for use by the user - this value is passed back into the callback function.
194 	 */
195 	int function(CPhidgetHandle phid, CPhidget_set_OnAttach_Handler_Func fptr, void* userPtr) CPhidget_set_OnAttach_Handler;
196 
197 	alias CPhidget_set_OnServerConnect_Handler_Func = extern(C) int function(CPhidgetHandle phid, void* userPtr);
198 	/**
199  	 * Sets a server connect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the server has been made.
200 	 *
201 	 * Params:
202 	 *	phid = A phidget handle.
203 	 *	fptr = Callback function pointer.
204 	 *	userPtr = A pointer for use by the user - this value is passed back into the callback function.
205 	 */
206 	int function(CPhidgetHandle phid, CPhidget_set_OnServerConnect_Handler_Func fptr, void* userPtr) CPhidget_set_OnServerConnect_Handler;
207 
208 	alias CPhidget_set_OnServerDisconnect_Handler_Func = extern(C) int function(CPhidgetHandle phid, void* userPtr);
209 	/**
210 	 * Sets a server disconnect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the server has been lost.
211 	 *
212 	 * Params:
213 	 *	phid = A phidget handle.
214 	 *	fptr = Callback function pointer.
215 	 *	userPtr = A pointer for use by the user - this value is passed back into the callback function.
216 	 */
217 	int function(CPhidgetHandle phid, CPhidget_set_OnServerDisconnect_Handler_Func fptr, void* userPtr) CPhidget_set_OnServerDisconnect_Handler;
218 
219 	alias CPhidget_set_OnError_Handler_Func = extern(C) int function(CPhidgetHandle phid, void* userPtr, int errorCode, const char* errorString);
220 	/**
221 	 * Sets the error handler callback function. This is called when an asynchronous error occurs.
222 	 *
223 	 * Params:
224 	 *	phid = A phidget handle.
225 	 * 	fptr = Callback function pointer.
226 	 * 	userPtr = A pointer for use by the user - this value is passed back into the callback function.
227 	 */
228 	int function(CPhidgetHandle phid, CPhidget_set_OnError_Handler_Func fptr, void* userPtr) CPhidget_set_OnError_Handler;
229 	
230 	/**
231 	 * Gets the specific name of a Phidget.
232 	 *
233 	 * Params:
234 	 *	phid = An attached phidget handle.
235 	 *	deviceName = A pointer which will be set to point to a char array containing the device name.
236 	 */
237 	int function(CPhidgetHandle phid, const char** deviceName) CPhidget_getDeviceName;
238 	
239 	/**
240 	 * Gets the serial number of a Phidget.
241 	 *
242 	 * Params:
243 	 *	phid = An attached phidget handle..
244 	 *	serialNumber = An int pointer for returning the serial number.
245 	 */
246 	int function(CPhidgetHandle phid, int* serialNumber) CPhidget_getSerialNumber;
247 	
248 	/**
249 	 * Gets the firmware version of a Phidget.
250 	 *
251 	 * Params:
252 	 *	phid = An attached phidget handle.
253 	 *	deviceVersion = An int pointer for returning the device version.
254 	 */
255 	int function(CPhidgetHandle phid, int* deviceVersion) CPhidget_getDeviceVersion;
256 	
257 	/**
258 	 * Gets the attached status of a Phidget.
259 	 *
260 	 * Params:
261 	 *	phid = A phidget handle.
262 	 *	deviceStatus = An int pointer for returning the device status. Possible are PHIDGET_ATTACHED and PHIDGET_NOTATTACHED.
263 	 */
264 	int function(CPhidgetHandle phid, int* deviceStatus) CPhidget_getDeviceStatus;
265 	
266 	/**
267 	 * Gets the library version. This contains a version number and a build date.
268 	 *
269 	 * Params:
270 	 *	libraryVersion = A pointer which will be set to point to a char array containing the library version string.
271 	 */
272 	int function(const char** libraryVersion) CPhidget_getLibraryVersion;
273 	
274 	/**
275 	 * Gets the type (class) of a Phidget.
276 	 *
277 	 * Params:
278 	 *	phid = An attached phidget handle.
279 	 *	deviceType = A pointer which will be set to a char array containing the device type string.
280 	 */
281 	int function(CPhidgetHandle phid, const char** deviceType) CPhidget_getDeviceType;
282 	
283 	/**
284 	 * Gets the label of a Phidget.
285 	 *
286 	 * Params:
287 	 *	phid = An attached phidget handle.
288 	 * 	deviceLabel = A pointer which will be set to a char array containing the device label string.
289 	 */
290 	int function(CPhidgetHandle phid, const char** deviceLabel) CPhidget_getDeviceLabel;
291 	
292 	/**
293 	 * Gets the label of a Phidget.
294 	 *
295 	 * Params:
296 	 *	phid = An attached phidget handle.
297 	 *	deviceLabel = A pointer which will be set to a char array containing the device label string.
298 	 */
299 	int function(CPhidgetHandle phid, const char* deviceLabel) CPhidget_setDeviceLabel;
300 	
301 	/**
302 	 * Gets the description for an error code.
303 	 *
304 	 * Params:
305 	 *	errorCode = The error code to get the description of.
306 	 *	errorString = A pointer which will be set to a char array containing the error description string.
307 	 */
308 	int function(int errorCode, const char** errorString) CPhidget_getErrorDescription;
309 	
310 	/**
311 	 * Waits for attachment to happen. This can be called right after calling CPhidget_open, as an alternative to using the attach handler.
312 	 *
313 	 * Params:
314 	 *	phid = An opened phidget handle.
315 	 *	milliseconds = Time to wait for the attachment. Specify 0 to wait forever.
316 	 */
317 	int function(CPhidgetHandle phid, int milliseconds) CPhidget_waitForAttachment;
318 	
319 	/**
320 	 * Gets the server ID fo a remotely opened Phidget. This will fail if the Phidget was opened locally.
321 	 *
322 	 * Params:
323 	 *	phid = A connected phidget handle.
324 	 *	serverID = A pointer which will be set to a char array containing the server ID string.
325 	 */
326 	int function(CPhidgetHandle phid, const char** serverID) CPhidget_getServerID;
327 	
328 	/**
329 	 * Gets the address and port of a remotely opened Phidget. This will fail f the Phidget was opened locally.
330 	 *
331 	 * Params:
332 	 *	phid = A connected phidget handle.
333 	 *	address = A pointer which will be set to a char array containing the address string.
334 	 *	port = An int pointer for returning the port number.
335 	 */
336 	int function(CPhidgetHandle phid, const char** address, int* port) CPhidget_getServerAddress;
337 	
338 	/**
339 	 * Gets the connected to server status of a remotely opened Phidget. This will fail if the Phidget was opened locally.
340 	 *
341 	 * Params:
342 	 *	phid = An opened phidget handle.
343 	 *	serverStatus = An int pointer for returning the server status. Possible codes are PHIDGET_ATTACHED and PHIDGET_NONATTACHED.
344 	 */
345 	int function(CPhidgetHandle phid, int* serverStatus) CPhidget_getServerStatus;
346 	
347 	/**
348 	 * Gets the device ID of a Phidget.
349 	 *
350 	 * Params:
351 	 *	phid = An attached phidget handle.
352 	 *	deviceID = The device ID constant.
353 	 */
354 	int function(CPhidgetHandle phid, CPhidget_DeviceID* deviceID) CPhidget_getDeviceID;
355 	
356 	/**
357 	 * Gets the class of a Phidget Handle.
358 	 *
359 	 * Params:
360 	 *	phid = A phidget handle.
361 	 *	deviceClass = The device class constant.
362 	 */
363 	int function(CPhidgetHandle phid, CPhidget_DeviceClass* deviceClass) CPhidget_getDeviceClass;
364 
365 	/**
366 	 * Opens a Phidget remotely by ServerID. Note that this requries Bonjour (mDNS) to be running on both the host and the server.
367 	 * 
368 	 * Params:
369 	 *  phid = A phidget handle.
370 	 *  serial = Serial number. Specify -1 to open any.
371 	 *  serverID = Server ID. Specify NULL to open any.
372 	 *  password = Password. Can be NULL if the server is running unsecured.
373 	 */
374 	int function(CPhidgetHandle phid, int serial, const char* serverID, const char* password) CPhidget_openRemote;
375 
376 	/**
377 	 * Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
378 	 * 
379 	 * Params:
380 	 *  phid = A phidget handle.
381 	 *  label = Label string. Labels can be up to 10 characters (UTF-8 encoding). Specify NULL to open any.
382 	 *  serverID = Server ID. Specify NULL to open any.
383 	 *  password = Password. Can be NULL if the server is running unsecured.
384 	 */
385 	int function(CPhidgetHandle phid, const char* label, const char* serverID, const char* password) CPhidget_openLabelRemote;
386 
387 	/**
388 	 * Opens a Phidget remotely by address and port, with optional serial number.
389 	 * 
390 	 * Params:
391 	 *  phid = A phidget handle.
392 	 *  serial = Serial number. Specify -1 to open any.
393 	 *  address = Address. This can be a hostname or IP address.
394 	 *  port = Port number. Default is 5001.
395 	 *  password = Password. Can be NULL if the server is running unsecured.
396 	 */
397 	int function(CPhidgetHandle phid, int serial, const char* address, int port, const char* password) CPhidget_openRemoteIP;
398 
399 	/**
400 	 * Opens a Phidget remotely by address and port, with optional label.
401 	 * 
402 	 * Params:
403 	 *  phid = A phidget handle.
404 	 *  label = Label string. Labels can be up to 10 characters (UTF-8 encoding). Specify NULL to open any.
405 	 *  address = Address. This can be a hostname or IP address.
406 	 *  port = Port number. Default is 5001.
407 	 *  password = Password. Can be NULL if the serer is running unsecured.
408 	 */
409 	int function(CPhidgetHandle phid, const char* label, const char* address, int port, const char* password) CPhidget_openLabelRemoteIP;
410 }